package cd.cdyb.sms.controller;


import cd.cdyb.sms.dto.PageResult;
import cd.cdyb.sms.dto.WhiteListDto;
import cd.cdyb.sms.dto.query.WhiteListQueryDto;
import cd.cdyb.sms.exception.BusinessException;
import cd.cdyb.sms.service.WhiteListService;
import cd.cdyb.sms.utils.UserUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

@RestController
@RequestMapping("/whiteList")
public class WhiteListController {

    @Resource
    private WhiteListService whiteListService;


    /**
     * 新增白名单
     *
     * @param whiteListDto 白名单
     */
    @PostMapping("/insertWhiteList")
    public void insertWhiteList(@RequestBody @Valid WhiteListDto whiteListDto) throws BusinessException {
        String currentName = UserUtils.getCurrentName();
        whiteListDto.setCreateName(currentName);
        whiteListService.insertWhiteList(whiteListDto);
    }

    /**
     * 编辑白名单
     *
     * @param whiteListDto 白名单
     */
    @PostMapping("/updateWhiteList")
    public void updateWhiteList(@RequestBody @Valid WhiteListDto whiteListDto)  {
        whiteListService.updateWhiteList(whiteListDto);
    }

    /**
     * 删除白名单
     *
     * @param whiteListDto 白名单ID
     */
    @PostMapping("/deleteWhiteListById")
    public void deleteWhiteListById(@RequestBody WhiteListDto whiteListDto)  {
        whiteListService.deleteWhiteListById(whiteListDto.getWhiteListId());
    }

    /**
     * 查询白名单分页
     *
     * @param whiteListQueryDto 查询条件
     * @return 白名单分页
     */
    @PostMapping("/findWhiteListPage")
    public PageResult<WhiteListDto> findWhiteListPage(@RequestBody WhiteListQueryDto whiteListQueryDto) throws BusinessException {
        return whiteListService.findWhiteListPage(whiteListQueryDto);
    }
}
